const sass = require('sass');
const loadGruntTasks = require('load-grunt-tasks');

module.exports = (grunt) => {
  grunt.initConfig({
    sass: {
      options: {
        sourceMap: true,
        implementation: sass,
      },
      main: {
        files: {
          'dist/css/main.css': 'src/scss/main.scss',
        },
      },
    },
    babel: {
      options: {
        sourceMap: true,
        presets: ['@babel/preset-env'],
      },
      main: {
        files: {
          'dist/js/app.js': 'src/js/app.js',
        },
      },
    },
    watch: {
      js: {
        files: ['src/js/*.js'],
        tasks: ['babel'],
      },
      css: {
        files: ['src/sass/*.scss'],
        tasks: ['sass'],
      },
    },
  });

  // 使用插件吧所有的 插件集中起来
  loadGruntTasks(grunt);

  grunt.registerTask('default', ['sass', 'babel', 'watch']);
};
